package com.lalameow.researchstation

import com.lalameow.researchstation.block.ResearchStationBlock
import com.lalameow.researchstation.block.ResearchStationBlockEntity
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap
import net.fabricmc.fabric.api.`object`.builder.v1.block.entity.FabricBlockEntityTypeBuilder
import net.minecraft.client.render.RenderLayer
import net.minecraft.util.registry.Registry

internal fun ResearchStation.registerBlock() = with(Blocks) {
    // 注册方块
    Registry.register(
        Registry.BLOCK,
        Identifiers.RESEARCH_STATION,
        RESEARCH_STATION
    )
    // 方块实体
    Registry.register(
        Registry.BLOCK_ENTITY_TYPE,
        Identifiers.RESEARCH_STATION,
        BlockEntities.RESEARCH_STATION
    )
}

@Environment(EnvType.CLIENT)
internal fun ResearchStation.registerBlockClient() = with(Blocks) {
    BlockRenderLayerMap.INSTANCE.putBlock(RESEARCH_STATION, RenderLayer.getTranslucent())
}

val ResearchStation.blocks: Blocks
    get() = Blocks

object Blocks {
    val RESEARCH_STATION = ResearchStationBlock
}

val ResearchStation.blockEntities: BlockEntities
    get() = BlockEntities

object BlockEntities {
    val RESEARCH_STATION =
        FabricBlockEntityTypeBuilder.create(::ResearchStationBlockEntity, Blocks.RESEARCH_STATION).build()!!
}
